/*
 * 文件名：LocalCouponServiceImpl.java	 
 * 时     间：下午5:39:04
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.dao.mapers.LocalCouponMapper;
import com.local.model.LocalCoupon;
import com.local.model.LocalCouponExample;
import com.local.page.LocalCouponPage;
import com.local.service.face.LocalCouponService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.Tools;
import common.cz0735.coustomer.mapers.CoustomerInfoMapper;
import common.cz0735.coustomer.model.CoustomerInfo;

@Service
public class LocalCouponServiceImpl extends BaseServiceImpl<LocalCouponExample, LocalCoupon, String> implements LocalCouponService
{
	@Autowired
	private LocalCouponMapper localCouponMapper;
	
	@Autowired
	private CoustomerInfoMapper coustomerInfoMapper;

	@Override
	public BaseMapper<LocalCouponExample, LocalCoupon, String> getMapper()
	{
		// TODO Auto-generated method stub
		return localCouponMapper;
	}

	@Override
	public List<LocalCoupon> findAllLocalCouponByQueryForm(
			LocalCouponPage<LocalCoupon> pageInfo)
	{
		Integer recordCount = localCouponMapper.countAllByPage(pageInfo);
		pageInfo.setTotalRecords(recordCount);
		List<LocalCoupon> list = localCouponMapper.queryByPage(pageInfo);
		for(LocalCoupon lc:list){
			if(!Tools.isEmpty(lc.getUserId())){
				CoustomerInfo coustomerInfo = coustomerInfoMapper.selectByPrimaryKey(lc.getUserId());
				if(!Tools.isEmpty(coustomerInfo)){
					lc.setUserName(coustomerInfo.getName());
				}
			}
		}
		pageInfo.setData(list);
		return list;
	}
	
	
	public Double queryCouponPriceByLoginUserId(LocalCoupon localCoupon){
		
		return localCouponMapper.selectCouponPrice(localCoupon);
	}

	@Override
	public List<LocalCoupon> queryByBillUuid(String BillUuid)
	{
		// TODO Auto-generated method stub
		LocalCouponExample contion=new LocalCouponExample();
		contion.or().andBillUuidEqualTo(BillUuid);
		List<LocalCoupon> localCouponLs=localCouponMapper.selectByCondition(contion);
		if(!Tools.isEmpty(localCouponLs)){
			return localCouponLs;
		}
		return null;
	}
}
